<?php

namespace App\Service\UserCenter\v1_3_4;

use App\Constants\FemaleKeepPushCode;
use App\Helpers\Helper;
use App\Job\FemaleKeepPushJob;
use App\Model\Message;
use App\Model\UserProfile;
use App\Service\BaseService;
use App\Service\Gift\FemalePushGiftService;
use App\Service\ServiceTrait\GetUserInfoTrait;
use function Symfony\Component\Translation\t;

class MyEntranceService extends BaseService
{
    use GetUserInfoTrait;
    public function handle(){
        $userId = $this->getUserId();

        $profile = $this->getUserInfo($userId);

        $channel = $this->request->input('channel', '');
        $version = $this->request->input('version', '');
        $forbidEntrance = config('busi.forbidEntrance_invitation');

        if ($channel == 1002){
            $ret['list'] = [
                $this->getValue('cost',$profile->gender == 0 ? 1 : 0),
                $this->getValue('account'),
                $this->getValue('identify'),
                $this->getValue('task'),
                $this->getValue('face'),
                $this->getValue('help'),
                $this->getValue('adolescent'),
                $this->getValue('setting'),
//                $this->getValue('invite', $inviteFlag ? 1 : 0)
            ];

            return $ret;
        }

        if (
            !((!empty($forbidEntrance) && isset($forbidEntrance[$channel]) && version_compare($version,$forbidEntrance[$channel],'=')) )
        ) {
            $inviteFlag = true;
        }else{
            $inviteFlag = false;
        }

        $ret['list'] = [
            $this->getValue('cost',$profile->gender == 0 ? 1 : 0),
            $this->getValue('account'),
            $this->getValue('identify'),
            $this->getValue('task'),
            $this->getValue('face'),
            $this->getValue('help'),
            $this->getValue('adolescent'),
            $this->getValue('setting'),
            $this->getValue('invite', $inviteFlag ? 1 : 0)
        ];

        return $ret;
    }


    function getValue($type,$show = 1): array
    {
        if (empty($type)){
            return [];
        }

        $icon = '';
        $title = '';
        switch ($type){
            case 'cost':
                $icon = 'http://xinyous-images.oss-cn-shenzhen.aliyuncs.com/icons/cost.png';
                $title = '资费设置';
                break;
            case 'account':
                $icon = 'http://xinyous-images.oss-cn-shenzhen.aliyuncs.com/icons/account.png';
                $title = '我的账户';
                break;
            case 'identify':
                $icon = 'http://xinyous-images.oss-cn-shenzhen.aliyuncs.com/icons/identify.png';
                $title = '认证中心';
                break;
            case 'task':
                $title = '任务中心';
                break;
            case 'face':
                $icon = 'http://xinyous-images.oss-cn-shenzhen.aliyuncs.com/icons/face.png';
                $title = '美颜设置';
                break;
            case 'help':
                $icon = 'http://xinyous-images.oss-cn-shenzhen.aliyuncs.com/icons/help.png';
                $title = '客服中心';
                break;
            case 'adolescent':
                $icon = 'http://xinyous-images.oss-cn-shenzhen.aliyuncs.com/icons/adolescent.png';
                $title = '青少年模式';
                break;
            case 'setting':
                $icon = 'http://xinyous-images.oss-cn-shenzhen.aliyuncs.com/icons/setting.png';
                $title = '设置';
                break;
            case 'invite':
                $title = '邀请好友';
                break;
        }

        return [
            'type' => $type,
            'icon' => $icon,
            'title' => $title,
            'show' => $show == 1 ? 1 : 0
        ];
    }
}